package com.zr.domain.bar.entity;

import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;

import java.io.Serializable;

public class MarketDataEvent implements Serializable {
    private String channel;
    private String instrument;
    private String contract;
    private long timestamp;
    private double open;
    private double high;
    private double low;
    private double close;

    public MarketDataEvent() {

    }

    public MarketDataEvent(String channel, String instrument, String contract, long timestamp, double open, double high, double low, double close) {
        this.channel = channel;
        this.instrument = instrument;
        this.contract = contract;
        this.timestamp = timestamp;
        this.open = open;
        this.high = high;
        this.low = low;
        this.close = close;
    }

    public MarketDataEvent(String message) {
    }


    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getInstrument() {
        return instrument;
    }

    public void setInstrument(String instrument) {
        this.instrument = instrument;
    }

    public String getContract() {
        return contract;
    }

    public void setContract(String contract) {
        this.contract = contract;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public double getOpen() {
        return open;
    }

    public void setOpen(double open) {
        this.open = open;
    }

    public double getHigh() {
        return high;
    }

    public void setHigh(double high) {
        this.high = high;
    }

    public double getLow() {
        return low;
    }

    public void setLow(double low) {
        this.low = low;
    }

    public double getClose() {
        return close;
    }

    public void setClose(double close) {
        this.close = close;
    }

    public String toJson() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(this);
    }

    public static MarketDataEvent fromJson(String json) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(json, MarketDataEvent.class);
    }

    public void setData(MarketDataEvent message) {

    }

    public MarketDataEvent getData() {
        return null;
    }

    @Override
    public String toString() {
        return "MarketData{" +
                "channel='" + channel + '\'' +
                ", instrument='" + instrument + '\'' +
                ", contract='" + contract + '\'' +
                ", timestamp=" + timestamp +
                ", open=" + open +
                ", high=" + high +
                ", low=" + low +
                ", close=" + close +
                '}';
    }
}
